package cn.cloud.butler.webapi.controller;

import cn.cloud.butler.webapi.domain.MacStateAlarmResult;
import cn.cloud.butler.webapi.domain.ResponseEntity;
import cn.cloud.butler.webapi.logger.WaLogger;
import cn.cloud.butler.webapi.service.MachinePushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * author: daichaoren
 * time: 2019-01-07
 * description: 推送类接口
 */
@RestController
@EnableAutoConfiguration
@RequestMapping("/HncWeb")
public class MachinePushController {
    @Autowired
    MachinePushService machinePushService;

    //接口 57：报警信息的推送
    //http://10.10.56.19:8084/HncWeb/AlarmTip.action?username=yxm
    @RequestMapping(method = RequestMethod.GET,value = "/AlarmTip.action")
    public ResponseEntity AlarmTip(String username) {
        ResponseEntity response = new ResponseEntity();

        try{
            List<HashMap<String,Object>> macStateAlarmResults = machinePushService.AlarmTip(username);
            response.setMsgCode(0);
            response.setMsgDesc("查询成功");
            response.setData(macStateAlarmResults);
        }catch (Exception e){
            response.setMsgCode(0);
            response.setMsgDesc(e.toString());
            WaLogger.logger.warn(e.toString());

        }
        return response;
    }

    //58. 机床周运行时间大幅下降推送
    @RequestMapping(method = RequestMethod.GET,value = "/WeekRunFallTip.action")
    public ResponseEntity weekRunFallTip(String username,Double percent){
        ResponseEntity respond = new ResponseEntity();
        List<HashMap<String,Object>> result;
        result = machinePushService.weekRunFallTip(username,percent);
        if(result.size()<=0){
            respond.setMsgCode(1);
            respond.setMsgDesc("无运行时间下降提醒");
        }else{
            respond.setMsgCode(0);
            respond.setMsgDesc("有运行时间下降提醒");
        }
        respond.setData(result);
        return respond;
    }

    // 59
    @RequestMapping(method = RequestMethod.GET,value = "/WeekOutputFallTip.action")
    public ResponseEntity weekOutputFallTip(String username, Double percent){
        ResponseEntity respond = new ResponseEntity();
        List<HashMap<String,Object>> data = machinePushService.weekOutputFallTip(username,percent);
        if(data == null || data.size() == 0){
            respond.setMsgCode(1);
            respond.setMsgDesc("上周产量无明显下降");
        }else{
            respond.setMsgCode(0);
            respond.setMsgDesc("上周产量有明显下降");
        }
        respond.setData(data);
        return respond;
    }

    // 60
    @RequestMapping(method = RequestMethod.GET,value = "/DayRunFallTip.action")
    public ResponseEntity DayRunFallTip(String username, Double percent){
        ResponseEntity respond = new ResponseEntity();
        List<HashMap<String,Object>> data = machinePushService.dayRunFallTip(username,percent);
        if(data == null || data.size() == 0){
            respond.setMsgCode(1);
            respond.setMsgDesc("昨日无运行时间下降提醒");
        }else{
            respond.setMsgCode(0);
            respond.setMsgDesc("昨日有运行时间下降提醒");
        }
        respond.setData(data);
        return respond;
    }

    // 61
    @RequestMapping(method = RequestMethod.GET,value = "/DayOutputFallTip.action")
    public ResponseEntity dayOutputFallTip(String username, Double percent){
        ResponseEntity respond = new ResponseEntity();
        List<HashMap<String,Object>> data = machinePushService.dayOutputFallTip(username,percent);
        if(data == null || data.size() == 0){
            respond.setMsgCode(1);
            respond.setMsgDesc("昨日产量无明显下降");
        }else{
            respond.setMsgCode(0);
            respond.setMsgDesc("昨日产量有明显下降");
        }
        respond.setData(data);
        return respond;
    }



}
